package com.guigu.tankai.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.tankai.mapper.MenuMapper;
import com.guigu.tankai.pojo.Menu;
import com.guigu.tankai.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    MenuMapper menuMapper;

    public List<Menu> Menus(Integer UserId){
        List<Menu> menuList = menuMapper.menus(1,UserId);
        for (Menu menu : menuList) {
            menu.setMenus(menuMapper.Menus(menu.getId(),UserId));
        }
        return menuList;
    }

    @Override
    public PageInfo<Menu> findByMenu(Integer page, Integer num, Menu menu) {
        PageHelper.startPage(page,num);
        List<Menu> byMenu = menuMapper.findByMenu(menu);
        return new PageInfo<Menu>(byMenu);    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return menuMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertSelective(Menu record) {
        return menuMapper.insertSelective(record);
    }

    @Override
    public Menu selectByPrimaryKey(Integer id) {
        return menuMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(Menu record) {
        return menuMapper.updateByPrimaryKey(record);
    }


}
